local skel = fk.CreateSkill {
  name = "emo__lingxi",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__lingxi"] = "灵犀",
  [":emo__lingxi"] = "锁定技，每轮开始时，若你未发动此技能，你令一名其他角色获得“灵”标记。其回合开始时，你获得其所有手牌，然后若其手牌数增加/减少，其回复/失去一点体力。",

  ["@[chara]emo__lingxi"] = "灵犀",
  ["@@emo__lingxi_other"] = "灵",
  ["#emo__lingxi-choose"] = "灵犀：令一名其他角色获得“灵”标记，其每回合开始时你获得其手牌",

  ["$emo__lingxi1"] = "此心相印，非山河可阻，兵戈可断。",
  ["$emo__lingxi2"] = "角中有白纹，灵如线，君心我心系两端。",
}

skel:addEffect(fk.RoundStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0 and table.find(player.room.alive_players, function (p)
      return p ~= player end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, { targets = room:getOtherPlayers(player), min_num = 1, max_num = 1,
     prompt = "#emo__lingxi-choose", skill_name = skel.name, cancelable = false})
    local to = tos[1]
    room:addPlayerMark(to, "@@emo__lingxi_other")
    room:setPlayerMark(player, "@[chara]emo__lingxi", to.id)
  end,
})

skel:addEffect(fk.TurnStart, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    return not target:isKongcheng() and target.id == player:getMark("@[chara]emo__lingxi")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local hand = target:getHandcardNum()
    room:obtainCard(player, target:getCardIds("h"), false, fk.ReasonPrey, player, skel.name)
    if target.dead then return end
    if target:getHandcardNum() > hand then
      room:recover {num = 1, skillName = skel.name, who = target, recoverBy = player}
    elseif target:getHandcardNum() < hand then
      room:loseHp(target, 1, skel.name)
    end
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  local mark = player:getMark("@[chara]emo__lingxi")
  if mark ~= 0 then
    player.room:setPlayerMark(player, "@[chara]emo__lingxi", 0)
    local to = player.room:getPlayerById(mark)
    player.room:removePlayerMark(to, "@[chara]emo__lingxi")
  end
end)

return skel
